package com.alon.spring01.service.impl;

import com.alon.spring01.mapper.UserMapper;
import com.alon.spring01.model.User;
import com.alon.spring01.service.CacheDemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: spring01
 * @description: 实现类
 * @author: yulongguang
 * @create: 2019-08-25 22:43
 **/
@Service
public class CacheDemoServiceImpl implements CacheDemoService {
    @Autowired
    private UserMapper userMapper;

    @Cacheable(value = "user", key = "#id")
    @Override
    public List<User> getFromDB(Integer id) {
        System.out.println("模拟去db查询~~~" + id);
        return userMapper.findById(id);
    }
}
